<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{BEESCRM:$title}</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/complaint/css/style.css">
    <link rel="stylesheet" href="/assets/complaint/css/layer.css">
</head>
<body>
<div class="wrapper">
    <div class="header header2 text-center">
        <a href="/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}" class="iconfont icon-zuo left"></a>
        <div class="font-16">申请</div>
    </div>
    <div class="main">

            <div class="content padding-12">
                <volist name="restaurants" id="vo">

                    <div class="list flex-2 ">
                        <span   type="checkbox" class="iconfont icon icon-weibiaoti2 green margin-r12"
                               data-value="{BEESCRM:$vo.restaurant_id}">
                        </span>
                        <div class="apply_img margin-r12">
                            <img onerror="this.src='/assets/complaint/images/house.jpg'" src="{BEESCRM:$vo.restaurant_img}" alt="">
                        </div>
                        <div>{BEESCRM:$vo.restaurant_name}</div>
                    </div>

                </volist>
            </div>

    </div>

    <span onclick="submit()" class="btn text-center font-16">提交申请</span>
    <!--<input type="submit" class="btn text-center font-16">提交申请</input>-->
</div>
</body>
<script src="/assets/complaint/js/public.js"></script>
<script src="/assets/complaint/js/layer.js"></script>
<script src="/assets/complaint/js/jquery-2.1.0.min.js"></script>
<script>
    $('.list').click(function () {
        var icon = $(this).children('.icon');
        if (icon.is('.icon-xuanzhong1')) {
            icon.removeClass('checked');
            //icon.attr('checked', false);
            icon.addClass('icon-weibiaoti2').removeClass('icon-xuanzhong1');
        } else {
//            icon.attr('checked', true);
            icon.addClass('checked');
            icon.addClass('icon-xuanzhong1').removeClass('icon-weibiaoti2');
        }
    });

    var height = $(window).height();
    var height2 = $('.btn').innerHeight();
    var height3 = $('.header').innerHeight();
    $('.main').css('height', height - height2 - height3);
</script>

<script>

    //表单提交1
    function submit() {

        //获取选中的值
        var restaurantids = [];
        for(i=0;i<$('.icon').length;i++){
            var icon = $('.icon').eq(i);
            if(icon.hasClass('checked')){
                restaurantids.push(icon.data('value'));
            }
        }


//            obj = document.getElementsByName("restaurants[]");
//            obj = $('.icon');

//            for(k in obj){
//                if(obj.eq(k).hasClass('checked'))
//                console.log(obj[k]);
//                    restaurantids.push(obj[k].data('value'));
//            }

//console.log(restaurantids);return;
        // 获取表单数据
        //document.getElementById("applyform").submit();

//        var restaurantids = getElements('applyform');
           // console.log(restaurantids);
        if (!restaurantids[0]) {
            fm.alert('没有选中任何公寓');
        } else {


            $.post(
                    '/Complaint/Common/applyRight/irs_id/{BEESCRM:$irs_id}',
                    {
                        'restaurants': restaurantids
                    },
                    function(data){

                        var data =JSON.parse(data);
                        //data: $('#applyform').serialize(),
                        if (data.status == 'S') {
                            fm.alert('申请成功,请等待处理!', 3);
                            //window.location.href='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}';
                            setTimeout("window.location='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}'", 1000);
                        } else {
                            fm.alert(data.message, 5);
                            //window.location.href='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}';
                            setTimeout("window.location='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}'", 1000);
                        }
                    }

            );
//
//            return false;
//            $.ajax({
//
//                url: '/Complaint/Common/applyRight/irs_id/{BEESCRM:$irs_id}', //提交给哪个执行
//                type: 'POST',
//                dataType: 'json',
//                async: false,
//                data: {
//                    restaurants: restaurantids
//                },
//                //data: $('#applyform').serialize(),
//                success: function (data) {
//                    if (data.status == 'S') {
//                        fm.alert('申请成功,请等待处理!', 3);
//                        //window.location.href='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}';
//                        setTimeout("window.location='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}'", 1000);
//                    } else {
//                        fm.alert(data.message, 5);
//                        //window.location.href='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}';
//                        setTimeout("window.location='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}'", 1000);
//                    }
//
//
//                },
////                error: function () {
////                    fm.alert('申请失败');
////                    //window.setTimeout("window.location='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}'", 1000);
////                    window.location.href='/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}';
////                }
//
//            });
        }
    }

    //获取指定form中的所有的<input>对象
//    function getElements(formId) {
//        var form = document.getElementById(formId);
//        var elements = new Array();
//        var tagElements = form.getElementsByTagName('input');
//        for (var j = 0; j < tagElements.length; j++) {
//            var restaurantid = inputSelector(tagElements[j]);
//            if (restaurantid) {
//                elements.push(restaurantid);
//            }
//        }
//        return elements;
//    }
//
//    //获取单个input中的【name,value】数组
//    function inputSelector(element) {
//        if (element.checked) {
//            return element.value;
//        }
//    }

</script>

</html>